package com.xx.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Set;

@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true) //告诉 Jackson 忽略JSON中所有未映射到Java类的字段
public class LoginUser implements UserDetails {
    //用户
    private User user;
    //权限
    private Set<String> setPermissions;

    public LoginUser(User user, Set<String> setPermissions) {
        this.user = user;
        this.setPermissions = setPermissions;
    }

    //权限
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    //账号是否过期
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }
    //账号是否锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }
    //密码是否过期
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }
    //账号是否可以
    @Override
    public boolean isEnabled() {
        return true;
    }
}
